package 程序员面试金典;

import java.util.Arrays;

public class 堆箱子 {

    public int pileBox(int[][] box) {
        Arrays.sort(box, (i, j) -> (i[0] != j[0] ? i[0] - j[0] : (i[1] != j[1] ? i[1] - j[1] : i[2] - j[2])));
        int[] dp = new int[box.length];
        for(int i = 0; i < dp.length; i++) {
            dp[i] = box[i][2];
            for(int j = 0; j < i; j++)
                if (box[i][0] > box[j][0] && box[i][1] > box[j][1] && box[i][2] > box[j][2])
                   dp[i] = Math.max(dp[i], box[i][2] + dp[j]);
        }
        Arrays.sort(dp);
        return dp[dp.length-1];
    }
}
